// 处理版本
const { redirect } = require('../util');
const { getRoute } = require('../routes');
const { parse, resolve } = require('path');
const { getConfig } = require('../config');
let { routePrefix } = getConfig();

module.exports = async function(ctx, next){
    let parsedUrl= parse(ctx.url);  
    // 以 html 结尾或者纯路径
    if(!ctx.path.includes(`${routePrefix}`) && !ctx.path.includes(`theme_`) && (parsedUrl.ext='.html' || (parsedUrl.ext==''))){
        let newPath = getRoute(ctx);
        console.log(`newPath: ${newPath}`);
        redirect(ctx, getRoute(ctx));
        return;
    }else{
        await next();
    }
}